package com.ctsi.offlinesupport.service;


import com.ctsi.commons.util.UtilValidate;
import com.ctsi.commons.util.id.UUIDGenerator;
import com.ctsi.commons.util.response.Page;
import com.ctsi.framework.common.exception.ExceptionFactory;
import com.ctsi.framework.mybatis.support.MybatisGenericDao;
import com.ctsi.supportflow.app.entity.SupportMeetRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * SupportMeetRecord Service 类
 * @author   liuhx
 * @description  SupportMeetRecord
 * @created	 Mon Oct 29 12:10:45 CST 2018
 */
@Service
public class SupportMeetRecordService {
	private static final Logger logger=LoggerFactory.getLogger(SupportMeetRecordService.class);
	@Autowired
	private MybatisGenericDao dao;
	@Autowired
    private ExceptionFactory exceptionFactory;
	/**
	 * 添加
	 */
	public SupportMeetRecord insertSupportMeetRecord(SupportMeetRecord supportMeetRecord){
		if(UtilValidate.isEmpty(supportMeetRecord.getId())) {
            supportMeetRecord.setId(UUIDGenerator.getId());
        }
		logger.debug("insert {}",supportMeetRecord);
		dao.insert(supportMeetRecord);

		return supportMeetRecord;
	}	
	/**
	 * 动态更新
	 */	
	public int updateSupportMeetRecordByPKSelective(SupportMeetRecord supportMeetRecord){
		logger.debug("updateByPrimaryKeySelective {}",supportMeetRecord);
		return dao.update(SupportMeetRecord.class.getName()+".updateByPrimaryKeySelective", supportMeetRecord);
	}
	/**
	 * 更新
	 */
	public int updateSupportMeetRecord(SupportMeetRecord supportMeetRecord){
		logger.debug("update {}",supportMeetRecord);
		return dao.update(supportMeetRecord);
	}
	
	
	public SupportMeetRecord editSupportMeetRecordById(String supportTaskId){
		if(UtilValidate.isEmpty(supportTaskId)) {
            return null;
        }
		logger.debug("editById {}",supportTaskId);
		return (SupportMeetRecord)dao.queryForObject(SupportMeetRecord.class.getName()+".edit", supportTaskId);
	}
	/**
	 * 根据ID查找 SupportMeetRecord对象
	 */
	public SupportMeetRecord findSupportMeetRecordById(String supportTaskId){
		if(UtilValidate.isEmpty(supportTaskId)) {
            return null;
        }
		logger.debug("findById {}",supportTaskId);
		return dao.get(SupportMeetRecord.class, supportTaskId);
	}

    public SupportMeetRecord findSupportMeetRecordBySupportId(String supportId){
        if(UtilValidate.isEmpty(supportId)) {
            return null;
        }
        logger.debug("findById {}",supportId);
        return (SupportMeetRecord)dao.queryForObject(SupportMeetRecord.class.getName()+".selectBySupportId", supportId);
    }
	/**
	 * 删除SupportMeetRecord对象
	 */
	public int removeSupportMeetRecord(String supportTaskId){	
		if(UtilValidate.isNotEmpty(supportTaskId)) {
            return dao.delete(SupportMeetRecord.class.getName()+".delete", supportTaskId);
        }
			//return dao.remove(supportTaskId);
		return 0;
	}
	
	/**
	 * 详细页查询
	 */
	public Map<String,Object> findByDetail(String supportTaskId){
		return (Map<String,Object>)dao.queryForObject(SupportMeetRecord.class.getName()+".findByDetail",supportTaskId);
	}
	/** 
	 * 多条件查询结果 
	 */
	public Page<Map<String,Object>> findByMulitCondition(Map<String,Object> param , int start , int pageSize){
		logger.debug("findByMulitCondition {}",param);
		if(pageSize<0||pageSize>2000) {
            pageSize=Page.DEFAULT_PAGE_SIZE;
        }
		if(start!=-1) {
            return dao.queryPage(SupportMeetRecord.class.getName()+".selectMulitCondition", param, start, pageSize);
        } else{
			throw new RuntimeException("参数不正确 !!");
		}
	}
	/** 
	 * 多条件查询结果不分页
	 */
	public List<?> find(Map<String,Object> map){
		logger.debug("find {}",map);
		return dao.queryForList(SupportMeetRecord.class.getName()+".selectByMap",map);
	}


	public boolean isSubmitMeet(String taskId){
	    Map<String,Object> params =new HashMap<>();
        params.put("taskId", taskId);
        long count = (long) dao.queryForObject(SupportMeetRecord.class.getName()+".verfyMeet", params);
        if (count>0){
            return true;
        }else{
            return false;
        }
    }
	
}
